using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VICC_VKQAJD
    {
        public DataRow Convert2ICC_VKQAJD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryICC_VKQAJD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["ROWNID"] = " ".PadRight(0 ); 
         dwReturn["ART"] = " ".PadRight(24 ); 
         dwReturn["COLOR"] = " ".PadRight(10 ); 
         dwReturn["TYP"] = " ".PadRight(10 ); 
         dwReturn["ITEM"] = " ".PadRight(5 ); 
         dwReturn["QIJD"] = " ".PadRight(10 ); 
         dwReturn["QIREM"] = " ".PadRight(100 ); 
         dwReturn["PATSTD"] = " ".PadRight(10 ); 
         dwReturn["PATNUM"] = " ".PadRight(10 ); 
         dwReturn["PATJD"] = " ".PadRight(10 ); 
         dwReturn["PATREM"] = " ".PadRight(100 ); 
         dwReturn["COLORJD"] = " ".PadRight(10 ); 
         dwReturn["COLORREM"] = " ".PadRight(100 ); 
         dwReturn["HANDJD"] = " ".PadRight(10 ); 
         dwReturn["HANDREM"] = " ".PadRight(100 ); 
         dwReturn["QCJD"] = " ".PadRight(10 ); 
         dwReturn["QCREM"] = " ".PadRight(100 ); 
         dwReturn["FINALJD"] = " ".PadRight(10 ); 
         dwReturn["FINALREM"] = " ".PadRight(100 ); 
         dwReturn["PROCESS"] = " ".PadRight(10 ); 
         dwReturn["PROCESSREM"] = " ".PadRight(100 ); 
         dwReturn["INSPDAT"] = " ".PadRight(20 ); 
         dwReturn["INSPECTOR"] = " ".PadRight(20 ); 
         dwReturn["INSPRATE"] = " ".PadRight(0 ); 
         dwReturn["QTY"] = " ".PadRight(0 ); 
         dwReturn["CUSTJD"] = " ".PadRight(10 ); 
         dwReturn["CUSTREM"] = " ".PadRight(100 ); 
         dwReturn["REMARK"] = " ".PadRight(200 ); 
         dwReturn["NEWUSER"] = " ".PadRight(8 ); 
         dwReturn["NEWTIME"] = " ".PadRight(20 ); 
         dwReturn["CHGUSER"] = " ".PadRight(8 ); 
         dwReturn["CHGTIME"] = " ".PadRight(20 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapICC_VKQAJD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveICC_VKQAJD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryICC_VKQAJD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapICC_VKQAJD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertICC_VKQAJD(dwLocal, ITXDBVERSION);
            }
            UpdateICC_VKQAJD(dwLocal);
        }
        public void InsertICC_VKQAJD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO ICC_VKQAJD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_VKQAJD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ICC_VKQAJD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM ICC_VKQAJD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "ICC_VKQAJD";
            Return = Result;
            return Return;
        }
        public void DeleteICC_VKQAJD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_VKQAJD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateICC_VKQAJD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE ICC_VKQAJD SET "
                    +"ROWNID= :ROWNID,"
                    +"ART= :ART,"
                    +"COLOR= :COLOR,"
                    +"TYP= :TYP,"
                    +"ITEM= :ITEM,"
                    +"QIJD= :QIJD,"
                    +"QIREM= :QIREM,"
                    +"PATSTD= :PATSTD,"
                    +"PATNUM= :PATNUM,"
                    +"PATJD= :PATJD,"
                    +"PATREM= :PATREM,"
                    +"COLORJD= :COLORJD,"
                    +"COLORREM= :COLORREM,"
                    +"HANDJD= :HANDJD,"
                    +"HANDREM= :HANDREM,"
                    +"QCJD= :QCJD,"
                    +"QCREM= :QCREM,"
                    +"FINALJD= :FINALJD,"
                    +"FINALREM= :FINALREM,"
                    +"PROCESS= :PROCESS,"
                    +"PROCESSREM= :PROCESSREM,"
                    +"INSPDAT= :INSPDAT,"
                    +"INSPECTOR= :INSPECTOR,"
                    +"INSPRATE= :INSPRATE,"
                    +"QTY= :QTY,"
                    +"CUSTJD= :CUSTJD,"
                    +"CUSTREM= :CUSTREM,"
                    +"REMARK= :REMARK,"
                    +"NEWUSER= :NEWUSER,"
                    +"NEWTIME= :NEWTIME,"
                    +"CHGUSER= :CHGUSER,"
                    +"CHGTIME= :CHGTIME,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString(); 
          or1.Parameters.Add("ART", OracleType.NVarChar).Value = dwData["ART"].ToString(); 
          or1.Parameters.Add("COLOR", OracleType.NVarChar).Value = dwData["COLOR"].ToString(); 
          or1.Parameters.Add("TYP", OracleType.NVarChar).Value = dwData["TYP"].ToString(); 
          or1.Parameters.Add("ITEM", OracleType.NVarChar).Value = dwData["ITEM"].ToString(); 
          or1.Parameters.Add("QIJD", OracleType.NVarChar).Value = dwData["QIJD"].ToString(); 
          or1.Parameters.Add("QIREM", OracleType.NVarChar).Value = dwData["QIREM"].ToString(); 
          or1.Parameters.Add("PATSTD", OracleType.NVarChar).Value = dwData["PATSTD"].ToString(); 
          or1.Parameters.Add("PATNUM", OracleType.NVarChar).Value = dwData["PATNUM"].ToString(); 
          or1.Parameters.Add("PATJD", OracleType.NVarChar).Value = dwData["PATJD"].ToString(); 
          or1.Parameters.Add("PATREM", OracleType.NVarChar).Value = dwData["PATREM"].ToString(); 
          or1.Parameters.Add("COLORJD", OracleType.NVarChar).Value = dwData["COLORJD"].ToString(); 
          or1.Parameters.Add("COLORREM", OracleType.NVarChar).Value = dwData["COLORREM"].ToString(); 
          or1.Parameters.Add("HANDJD", OracleType.NVarChar).Value = dwData["HANDJD"].ToString(); 
          or1.Parameters.Add("HANDREM", OracleType.NVarChar).Value = dwData["HANDREM"].ToString(); 
          or1.Parameters.Add("QCJD", OracleType.NVarChar).Value = dwData["QCJD"].ToString(); 
          or1.Parameters.Add("QCREM", OracleType.NVarChar).Value = dwData["QCREM"].ToString(); 
          or1.Parameters.Add("FINALJD", OracleType.NVarChar).Value = dwData["FINALJD"].ToString(); 
          or1.Parameters.Add("FINALREM", OracleType.NVarChar).Value = dwData["FINALREM"].ToString(); 
          or1.Parameters.Add("PROCESS", OracleType.NVarChar).Value = dwData["PROCESS"].ToString(); 
          or1.Parameters.Add("PROCESSREM", OracleType.NVarChar).Value = dwData["PROCESSREM"].ToString(); 
          or1.Parameters.Add("INSPDAT", OracleType.NVarChar).Value = dwData["INSPDAT"].ToString(); 
          or1.Parameters.Add("INSPECTOR", OracleType.NVarChar).Value = dwData["INSPECTOR"].ToString(); 
          or1.Parameters.Add("INSPRATE", OracleType.NVarChar).Value = dwData["INSPRATE"].ToString(); 
          or1.Parameters.Add("QTY", OracleType.NVarChar).Value = dwData["QTY"].ToString(); 
          or1.Parameters.Add("CUSTJD", OracleType.NVarChar).Value = dwData["CUSTJD"].ToString(); 
          or1.Parameters.Add("CUSTREM", OracleType.NVarChar).Value = dwData["CUSTREM"].ToString(); 
          or1.Parameters.Add("REMARK", OracleType.NVarChar).Value = dwData["REMARK"].ToString(); 
          or1.Parameters.Add("NEWUSER", OracleType.NVarChar).Value = dwData["NEWUSER"].ToString(); 
          or1.Parameters.Add("NEWTIME", OracleType.NVarChar).Value = dwData["NEWTIME"].ToString(); 
          or1.Parameters.Add("CHGUSER", OracleType.NVarChar).Value = dwData["CHGUSER"].ToString(); 
          or1.Parameters.Add("CHGTIME", OracleType.NVarChar).Value = dwData["CHGTIME"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
